library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggridges)
weather_df =
rnoaa::meteo_pull_monitors(
c("USW00094728", "USW00022534", "USS0023B17S"),
var = c("PRCP", "TMIN", "TMAX"),
date_min = "2021-01-01",
date_max = "2022-12-31") |>
mutate(
name = recode(
id,
USW00094728 = "CentralPark_NY",
USW00022534= "Molokai_HI",
USS0023B17S = "Waterhole_WA"),
tmin = tmin / 10,
tmax = tmax / 10) |>
select(name, id, everything())
## using cached file: /Users/mingzhichen/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USW00094728.dly
## date created (size, mb): 2023-09-28 10:20:33.812229 (8.524)
## file min/max dates: 1869-01-01 / 2023-09-30
## using cached file: /Users/mingzhichen/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USW00022534.dly
## date created (size, mb): 2023-09-28 10:20:39.096099 (3.83)
## file min/max dates: 1949-10-01 / 2023-09-30
## using cached file: /Users/mingzhichen/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USS0023B17S.dly
## date created (size, mb): 2023-09-28 10:20:40.986201 (0.994)
## file min/max dates: 1999-09-01 / 2023-09-30
ggplot(weather_df,aes(x=tmin,y=tmax))+
geom_point()
## Warning: Removed 17 rows containing missing values (`geom_point()`).
weather_df |>
filter(name=="CentralPark_NY") |>
ggplot(aes(x=tmin,y=tmax))+
geom_point()
fancy plots
ggplot(weather_df,aes(x=tmin,y=tmax,color=name))+
geom_point()+
geom_smooth()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 17 rows containing missing values (`geom_point()`).
ggplot(weather_df,aes(x=tmin,y=tmax))+
geom_point(aes(color=name),alpha=0.3)+
geom_smooth(se= FALSE)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 17 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 17 rows containing missing values (`geom_point()`).
ggplot(weather_df,aes(x=tmin,y=tmax,color=name))+
geom_point(alpha=0.3)+
geom_smooth(se= FALSE)+
facet_grid(.~name)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 17 rows containing missing values (`geom_point()`).
ggplot(weather_df,aes(x=date,y=tmax,color=name))+
geom_point(aes(size=prcp),alpha=0.3)+
geom_smooth(se= FALSE)+
facet_grid(.~name)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 19 rows containing missing values (`geom_point()`).
weather_df |>
filter(name!="CentralPark_NY") |>
ggplot(aes(x=date,y=tmax,color=name))+
geom_point(alpha=0.7,size=0.5)
## Warning: Removed 17 rows containing missing values (`geom_point()`).
weather_df |>
ggplot(aes(x=tmin,y=tmax))+
geom_hex()
## Warning: Removed 17 rows containing non-finite values (`stat_binhex()`).
ggplot(weather_df,aes(x=tmax,color=name))+
geom_histogram(position = "dodge")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 17 rows containing non-finite values (`stat_bin()`).
ggplot(weather_df,aes(x=tmax,fill=name))+
geom_density(alpha=0.3,adjust=2)
## Warning: Removed 17 rows containing non-finite values (`stat_density()`).
ggplot(weather_df,aes(y=tmax,x=name))+
geom_boxplot()
## Warning: Removed 17 rows containing non-finite values (`stat_boxplot()`).
ggplot(weather_df,aes(y=tmax,x=name))+
geom_violin()
## Warning: Removed 17 rows containing non-finite values (`stat_ydensity()`).
ggplot(weather_df,aes(x=tmax,y=name))+
geom_density_ridges()
## Picking joint bandwidth of 1.54
## Warning: Removed 17 rows containing non-finite values
## (`stat_density_ridges()`).
weather_df|>
filter(name=="Molokai_HI")|>
ggplot(aes(x=date,y=tmax))+
geom_line(alpha=0.5)+
geom_point(size=.5)
## Warning: Removed 1 rows containing missing values (`geom_point()`).
ggp_weather=
weather_df|>
ggplot(aes(x=tmin,y=tmax))+
geom_point()
ggsave("results/ggp_weather.pdf",ggp_weather)
## Saving 7 x 5 in image
## Warning: Removed 17 rows containing missing values (`geom_point()`).
ggp_weather
## Warning: Removed 17 rows containing missing values (`geom_point()`).